package com.mc.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool {
	public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 10, 200, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<Runnable>(5));
		for(int i=0;i<10;i++){
			MyTask task = new MyTask(i);
			executor.execute(task);
			 System.out.println("线程池中线程数目："+executor.getPoolSize()+"，队列中等待执行的任务数目："+
		             executor.getQueue().size()+"，已执行玩别的任务数目："+executor.getCompletedTaskCount());
		}
		executor.shutdown();
	}
}
class MyTask implements Runnable {
	private int num;
	public MyTask(int num){
		this.num = num;
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		System.out.println("开始执行:"+num);
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("执行结束:"+num);
	}
}
